package com.qsmx.store.app.main.goods.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.qsmx.store.app.R;
import com.qsmx.store.app.main.goods.entity.GoodsOrderEntity;
import com.qsmx.store.app.main.goods.holder.GoodsOrderHolder;

import java.util.List;

public class GoodsOrderAdapter extends RecyclerView.Adapter<GoodsOrderHolder> {
    private Context mContext;
    private List<GoodsOrderEntity.ContentBean.GoodsSellDetailsBean> mData;

    public void setData(List<GoodsOrderEntity.ContentBean.GoodsSellDetailsBean> mData) {
        this.mData = mData;
    }

    public GoodsOrderAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public GoodsOrderHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new GoodsOrderHolder(LayoutInflater.from(mContext).inflate(R.layout.adapter_goods_order, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsOrderHolder goodsOrderHolder, int position) {
        GoodsOrderEntity.ContentBean.GoodsSellDetailsBean data = mData.get(position);
        goodsOrderHolder.tvGoodsName.setText(data.getGoodsName());
        goodsOrderHolder.tvGoodsSku.setText(data.getGoodsCode());
        goodsOrderHolder.tvGoodsNum.setText(String.valueOf(data.getDetailNum()));
        goodsOrderHolder.tvReceivableOneMoney.setText(String.valueOf(data.getPrice()));
        goodsOrderHolder.tvActualMoney.setText(String.valueOf(data.getMoney()));
    }

    @Override
    public int getItemCount() {
        if (mData != null && mData.size() > 0) {
            return mData.size();
        } else {
            return 0;
        }
    }
}
